<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of soa2Logs
 *
 * @author dxx
 */

namespace app\common\model\log;

use think\Model;

class CompanyPointLog extends Model {

    protected $table = 'jj_company_point_log';
    protected $connection = ['database' => 'jooj_log'];
    
    /**
     * 通过条件获取公司积分点日志
     * @param type $condition
     * @param type $field
     * @return type
     */
    public function getCompanyPointLogByCondition($condition,$field='*'){
        return $this->where($condition)->field($field)->find();
    }
    
    
    /**
     * 插入积分点日志
     * @param type $params
     * @return type
     */
    public function addCompanyPointLog($params){
        
        $data = [
            'o_id'=>$params['o_id'],
            'staff_id'=>$params['staff_id'],
            'action'=>$params['action'],
            'point'=>$params['point'],
            'status'=>$params['status'],
            'comment'=>$params['comment'],
            'rule_id'=>$params['rule_id'],
            'store_id'=>$params['store_id'],
            'store_name'=>$params['store_name'],
            'add_ts'=>time()
        ];
        
        $data = array_filter($data);
        
        return $this->insertGetId($data);
    }
    
    /**
     * 保存状态
     * @param type $id
     * @param type $status
     * @return type
     */
    public function saveStatus($id,$status){
        return $this->where(['id'=>$id])->update(['status'=>$status]);
    }
}
